<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('订货申请新增及修改')" />
	<th:block th:include="include :: businessCSS" />
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
	    <div class="north">
            <th:block th:include="include :: business_btn" />
	        <th:block th:include="include :: business_tpl('top')" />
    	</div>
	    <div class="mid-content">
	        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	    </div>
	    <th:block th:include="include :: pageFooter" /> 
        </form>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: businessTableBtn" />
<th:block th:include="include :: inlineJS" />
<script type="text/javascript">
var $,layer,form,table,laydate,element;//定义layui模块
eachFields();//明细表格中的字段遍历
layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
 	beforeInit();//表单初始化之前的动作集合
 	layui.element.render();
 	$.get("/business/ordernew/listbynid?nid="+nid,function(data){
		$.each(data.data,function(k,v){
			dataStr.push(v);
		});
		initTable();//初始化表格
	});
	toolEvent('ftable');//行event事件监听
	monitorSort();//监听排序——重载赋值渲染
	moneyCalculation();//表格编辑——资金计算
	//头部event事件
	table.on('toolbar(ftable)', function(obj){
		var checkStatus = table.checkStatus('dhtable');
	    switch(obj.event){
	    	case 'addBtn':
	    		if(listData.length > 0){
	    			if(listData[listData.length - 1]['iid']){
	    				gridColumns.gridNewLine.iid = Number(listData[listData.length - 1]['iid']) + 1;//行号自增1
	    			}else{
	    				gridColumns.gridNewLine.iid = 1;
	    			}
	    		}else{
	    			gridColumns.gridNewLine.iid = 1;
	    		}
	    		listData.push(gridColumns.gridNewLine);
	        	table.reload('dhtable', {data : listData});
	      		form.render();
	    	break;
	    	case 'deleteBatch':
	    		tableDeleteBatch('dhtable', listData, checkStatus);
	    	break;
	    	case 'fieldSet':
	    		filedSet(moduleTable+'_EditPage202109');
         	break;
			case 'tableFull'://表格展开
				$('.north .layui-form').hide();
				table.reload('dhtable',{
					defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'tableShrink'://表格收缩
				$('.north .layui-form').show();
				table.reload('dhtable',{
					defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
	    	case 'importBtn':
	    		$.tablelist.importExcel('dhtable',importFields, table.cache.dhtable, moduleTable, decimalObj);
         	break;
	    	case 'notice'://通知采购_生成功能任务
	    		var url="/system/moduletask/add";//拼接url并传参数到页面赋值
	    			url+="?pt=订货申请";
	    			url+="&ta=单据编号:【"+$('#bid').val()+"】;付款方式:【"+$('#vFkFsName').val()+"】;"
	    				+"提货要求:【"+(gridColumns.readOnly?$('#vThYqName').val():$('#vThYqName option:selected').text())+"】;销售员:【"+$('#gUserName').val()+"】。";
	    			url+="&pg="+nid;
	    			url+="&pu="+window.location.pathname;
	    		layer.open({
            		type: 2,
            		area: [($(window).width() - 400)+'px', ($(window).height() - 200)+'px'],
            		fix: false,//不固定
            		offset: '10%',//距离顶部
            		maxmin: true,//最大最小化
            		shade: 0.3,//遮罩
            		title: '通知采购',
            		content: url,
            		btn: ['确定', '取消'],
            		shadeClose: true,// 弹层外区域关闭
            		yes: function(index, layero){
            			var res = window["layui-layer-iframe" + index].callbackdata();
            			if(res){
                			$.operate.post('/system/moduletask/addModuleTask', res ,function(result){
                				if(result.code==0)layer.close(index);
                			});
            			}else layer.msg('请选择接收人！',{icon:7});
            		}
            	});
	    		break;
	    };
	});
})

function btn1(dcache){//功能任务——通知技术——回复
	var url="/edi/specialorder/notice";
		url+="?tc=您有一份【订货申请（"+$('#bid').val()+"）】任务已通过采购处理。";
		url+="&ta=单据编号:【"+$('#bid').val()+"】;付款方式:【"+$('#vFkFsName').val()+"】;"
		+"提货要求:【"+(gridColumns.readOnly?$('#vThYqName').val():$('#vThYqName option:selected').text())+"】;销售员:【"+$('#gUserName').val()+"】。";
		url+="&pg="+nid;//拼接url并传参数到页面赋值
		url+="&cu="+dcache['bUser'];//拼接url并传参数到页面赋值
		url+="&cun="+dcache['bUserName'];//拼接url并传参数到页面赋值
	layer.open({
		type: 2,
		area: ['100%','100%'],
		title: '回复采购',
		content: url,
		btn: ['确定', '取消'],
		shadeClose: true,// 弹层外区域关闭
		yes: function(index, layero){
			var res = window["layui-layer-iframe" + index].callbackdata();
			if(res){
				$.each(res,function(i,v){
					dcache[i]=v;
				})
    			dcache['pageURL']='/edi/ordernew/edit?nid='+nid;
    			dcache['moduleTable']='Commonality';
    			dcache['taskState']='未读';
    			dcache['taskTaskState']='已处理';//改变功能任务状态需要
    			$.operate.post('/system/moduletask/reply', dcache ,function(result){
    				if(result.code==0)layer.close(index);
    			});
			}else layer.msg('请选择接收人！',{icon:7});
			return true;
		}
	});
}
</script>
</body>
</html>